using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

using GSN.Rules;
using GSNConf.Rules.ConfigControls;
using GSN.Config;
using GSNConf.GenConfigControls;

namespace GSNConf.Rules
{
    class AllowedSendersRuleConfigurator : IConfigurator
    {
        private string[] senders = null;

        #region IConfigurator Members

        string[] IConfigurator.getItemStringArray(string key)
        {
            return senders;
        }

        void IConfigurator.setItemStringArray(string[] value, string key)
        {
            senders = value;
        }

        void IConfigurator.setItemString(string value, string key)
        {
            throw new NotImplementedException();
        }

        string IConfigurator.getItemString(string key)
        {
            throw new NotImplementedException();
        }

        bool IConfigurator.show()
        {
            GenConfigForm form = new GenConfigForm(new AllowedSendersRuleConfigControl(), "Rule Settings");

            ListBox lst = (ListBox)form.Controls.Find("lstSenders", true)[0];

            if (senders != null)
            {         
                lst.Items.AddRange(senders);
            }

            if (form.ShowDialog() == DialogResult.OK)
            {
                List<string> sList = new List<string>();

                foreach (string s in lst.Items)
                {
                    sList.Add(s);
                }

                senders = sList.ToArray();

                return true;
            }

            return false;
        }

        #endregion
    }
}
